<?php
require_once('includes/config.php');

if ( (isset($_GET['id'])) && (isset($_GET['getcode'])) ) {
        require_once('includes/phpqrcode/qrlib.php');
	if (isset($_GET['download'])) { header('Content-disposition: attachment; filename='.$_GET['id'].'.png'); header('Content-type: image/png');}
        QRcode::png(INSTALL_PATH.$_GET['id'], false, 'L', 4, 2);

} elseif (isset($_GET['id'])) {
	if (REWRITE) { $qrcode=INSTALL_PATH.'qr/'.$_GET['id'].'.png'; } else { $qrcode=INSTALL_PATH.'qr.php?getcode&id='.$_GET['id']; }
	echo '<div style="width: 550px; height: 240px;"><br /><script type="text/javascript" src="ZeroClipboard.js"></script>';
	echo '<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>';
	echo '<link rel=StyleSheet href="'.INSTALL_PATH.'includes/style.css">';
	echo '<a href="'.INSTALL_PATH.'qr.php?getcode&download&id='.$_GET['id'].'"><img src="'.$qrcode.'"></a>';
	echo '<div class=success-display id="d_clip_button_qr" style=\"display:block;\" \">Here you go: '.$qrcode.' <br /><i><div class="clicktocopyqr">Click to copy</div></i> <script language="JavaScript">var clipqr = new ZeroClipboard.Client();clipqr.setText( \''.$qrcode.'\' ); $(window).load(function(){ clipqr.glue( \'d_clip_button_qr\' ); });</script></div></div>';
?>
<script>
clipqr.addEventListener( 'onComplete', changeclipmsgqr );
function changeclipmsgqr( client, text ) {
        $('div.clicktocopyqr').replaceWith('Copied to Clipboard');
};
</script>
<?php
}
?>

